package com.study.apacheutil;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.jupiter.api.Test;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author zhuzi
 * 2024/5/20 9:49
 */
public class ColDemo {
    @Test
    public void sub() {

        List<String> listA = new ArrayList<>();
        listA.add("a");
        listA.add("b");
        listA.add("b");
        listA.add("b");
        listA.add("c");
        List<String> listB = new ArrayList<>();
        listB.add("a");
        listB.add("e");
        listB.add("f");
        System.out.println("集合A:" + listA);
        System.out.println("集合B:" + listB);
        System.out.println("------------------------");
        //并集
        Collection<String> union = CollectionUtils.union(listA, listB);
        System.out.println("并集：" + union);
        //交集
        Collection<String> intersection = CollectionUtils.intersection(listA, listB);
        System.out.println("交集：" + intersection);
        //交集的补集
        Collection<String> disjunction = CollectionUtils.disjunction(listA, listB);
        System.out.println("交集的补集   ：" + disjunction);
        //差集(集合相减)
        Collection<String> subtract = CollectionUtils.subtract(listA, listB);
        System.out.println("差集(集合相减)   ：" + subtract);
        System.out.println("集合A:" + listA);
        System.out.println("集合B:" + listB);
    }

    @Test
    public void col() {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        Collections.sort(list);//升序
        System.out.println(list);
        Collections.reverse(list);//降序
        System.out.println(list);
    }

    @Test
    public void colMax() {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        Integer max = Collections.max(list);//获取最大值
        Integer min = Collections.min(list);//获取最小值
        System.out.println(max);
        System.out.println(min);
    }

    @Test
    public void colUnion() {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);

        List<Integer> list2 = new ArrayList<>();
        list2.add(2);
        list2.add(4);

        System.out.println("集合A:" + list);
        System.out.println("集合B:" + list2);
        //获取并集
        Collection<Integer> unionList = CollectionUtils.union(list, list2);
        System.out.println("并集 " + unionList);

        //获取交集
        Collection<Integer> intersectionList = CollectionUtils.intersection(list, list2);
        System.out.println("交集 " + intersectionList);

        //获取交集的补集
        Collection<Integer> disjunctionList = CollectionUtils.disjunction(list, list2);
        System.out.println("交集的补集" + disjunctionList);

        //获取差集
        Collection<Integer> subtractList = CollectionUtils.subtract(list, list2);
        System.out.println(subtractList);
    }

    @Test
    public void demo() {
        String str = null;
        Assert.isNull(str, "str必须为空");
        Assert.isNull(str, () -> "str必须为空");
        Assert.notNull(str, "str不能为空");
    }
}
